#ifndef SETTINGSMANAGERSINGLETON_H
#define SETTINGSMANAGERSINGLETON_H

#include <QObject>
#include <QSharedPointer>
#include <QTime>
#include <QSettings>

const QString KEY_LANG = "lang";
const QString KEY_DIR_IMAGES = "directories/imagesDirPath";
const QString KEY_DIR_VIDEOS = "directories/videosDirPath";
const QString KEY_DIR_AUTOSNAPPING = "directories/autoSnappingDirPath";
const QString KEY_DIR_MOTION = "directories/motionDirPath";
const QString KEY_EMAIL_SERVERTYPE = "email/serverType";
const QString KEY_EMAIL_SERVERPORT = "email/serverPort";
const QString KEY_EMAIL_SERVERADDRESS = "email/serverAddress";
const QString KEY_EMAIL_SENDER = "email/emailSender";
const QString KEY_EMAIL_SENDERPWD = "email/password";
const QString KEY_EMAIL_RECEIVERS = "email/receivers";
const QString KEY_EMAIL_HIDEPWD = "email/hidePassword";
const QString KEY_EMAIL_DONTREMEMBERPWD = "email/dontRememberPassword";
const QString KEY_AUTOSNAPPING_INTERVAL = "autoSnapping/interval";
const QString KEY_AUTOSNAPPING_SENDEMAIL = "autoSnapping/sendEmail";
const QString KEY_MOTION_INTERVAL = "motion/interval";
const QString KEY_MOTION_SENSIBILITY = "motion/sensibility";
const QString KEY_MOTION_SENDEMAIL = "motion/sendEmail";
const QString KEY_MOTION_SENDIMAGE = "motion/sendImage";
const QString KEY_MOTION_SAVE = "motion/save";
const QString KEY_MOTION_SAVEIMAGE = "motion/saveImage";
const QString KEY_MOTION_SAVEVIDEO = "motion/saveVideo";

class SettingsManagerSingleton : public QObject{
    Q_OBJECT
public:
    static SettingsManagerSingleton *getInstance();
    QString getLanguage();
    QString getImagesTestFilePath();
    QString getImagesDirPath();
    QString getVideosDirPath();
    QString getAutoSnappingDirPath();
    QString getMotionDirPath();
    QString getServerType();
    int getServerPort();
    QString getServerAddress();
    QString getEmailSender();
    bool getHidePasswordSender();
    bool getDontRememberPasswordSender();
    QString getPasswordSender();
    QString getEmailReceivers();
    QTime getAutoSnappingTimeInterval();
    int getAutoSnappingTimeIntervalInMs();
    bool getAutoSnappingSendEmail();
    int getMotionTimeInterval();
    int getMotionSensibility();
    bool getMotionSendEmail();
    bool getMotionSendEmailWithImage();
    bool getMotionSave();
    bool getMotionSaveImage();
    bool getMotionSaveVideo();

signals:
    void languageChanged(QString language);
    void imagesDirPathChanged(QString imagesDirPath);
    void videosDirPathChanged(QString videosDirPath);
    void autoSnappingDirPathChanged(QString autoSnappingDirPath);
    void motionDirPathChanged(QString momtionDirPath);
    void emailInformationChanged();
    void hidePasswordSenderChanged(bool hidePassword);
    void dontRememberPasswordSenderChanged(bool dontRemember);
    void autoSnappingTimeIntervalChanged(QTime interval);
    void motionTimeIntervalChanged(int ms);

public slots:
    void setLanguage(QString language);
    void setImagesDirPath(QString imagesDirPath);
    void setVideosDirPath(QString videosDirPath);
    void setAutoSnappingDirPath(QString autoSnappingDirPath);
    void setMotionDirPath(QString momtionDirPath);
    void setServerType(QString serverType);
    void setServerPort(int serverPort);
    void setServerAddress(QString serverAddress);
    void setEmailSender(QString emailSender);
    void setHidePasswordSender(bool hidePassword);
    void setDontRememberPasswordSender(bool dontRemember);
    void setPasswordSender(QString password);
    void setEmailReceivers(QString receivers);
    void setAutoSnappingTimeInterval(QTime interval);
    void setAutoSnappingSendEmail(bool sendEmail);
    void setMotionTimeInterval(int ms);
    void setMotionSensibility(int sensibility);
    void setMotionSendEmail(bool sendEmail);
    void setMotionSendEmailWithImage(bool sendImage);
    void setMotionSave(bool saveImage);
    void setMotionSaveImage(bool saveImage);
    void setMotionSaveVideo(bool saveVideo);

private:
    explicit SettingsManagerSingleton(QObject *parent = 0);
    static QSharedPointer<SettingsManagerSingleton> instance;
    QString _getValidDirPath(QString dirPath);
    QSettings *settings;
    QString passwordSender;
};

#endif // SETTINGSMANAGER_H
